<template>
  <div class="trade-box">
    <!-- 买卖 -->
    <h3 class="title">填写并核对订单信息</h3>
    <div class="content">
      <Address />
      <div class="pay-box">
        <span class="pay-title">支付方式</span>
        <div class="pay-select clearFix">
          <span class="username selected">在线支付</span>
          <span class="username">货到付款</span>
        </div>
      </div>
      <div class="inventory-box">
        <span class="inventory-title">送货清单</span>
        <div class="inventory-list">
          <div class="delive">
            <span class="delive-title">配送方式</span>
            <div class="info clearFix">
              <span class="s1">天天快递</span>
              <p>配送时间</p>
              <p>预计8月10日（周三）09:00-15:00送达</p>
            </div>
          </div>
          <div class="goods-list">
            <span class="detail-title">商品清单</span>
            <div class="detail">
              <ul
                class="list clearFix"
                v-for="order in getDetailList"
                :key="order.skuId"
              >
                <li class="img-url">
                  <img :src="order.imgUrl" alt="" />
                </li>
                <li class="goods-name">
                  <p>
                    {{ order.skuName }}
                  </p>
                  <span>7天无理由退货</span>
                </li>
                <li class="goods-price">
                  <h3>￥{{ order.orderPrice }}</h3>
                </li>
                <li class="goods-num">X{{ order.skuNum }}</li>
                <li class="goods-stock">有货</li>
              </ul>
            </div>
            <div class="bbs">
              <span>买家留言：</span>
              <textarea
                placeholder="建议留言前先与商家沟通确认"
                class="remarks-cont"
                v-model="msg"
              ></textarea>
            </div>
          </div>
        </div>
      </div>
      <div class="bill">
        <h5>发票信息：</h5>
        <div>普通发票（电子） 个人 明细</div>
        <h5>使用优惠/抵用</h5>
      </div>
      <div class="money clearFix">
        <ul>
          <li>
            <b
              ><i>{{ orderInfo.totalNum }}</i
              >件商品，总商品金额</b
            >
            <span>¥{{ orderInfo.totalAmount }}</span>
          </li>
          <li>
            <b>返现：</b>
            <span>0.00</span>
          </li>
          <li>
            <b>运费：</b>
            <span>0.00</span>
          </li>
        </ul>
      </div>
      <div class="trade">
        <div class="price">
          应付金额:　<span>¥{{ orderInfo.originalTotalAmount }}</span>
        </div>
        <div class="receiveInfo">
          寄送至:
          <span>{{ address.fullAddress }}</span>
          收货人：<span>{{ address.consignee }}</span>
          <span>{{ address.phoneNum }}</span>
        </div>
      </div>
      <div class="sub clearFix">
        <a class="subBtn" @click.prevent="submitOrder">提交订单</a>
      </div>
    </div>
  </div>
</template>

<script>
import Address from "./Address";
import { mapGetters, mapState } from "vuex";
export default {
  name: "Trade",
  components: { Address },
  data() {
    return {
      msg: "",
    };
  },
  computed: {
    //获取订单列表
    ...mapState("order", ["orderInfo"]),
    ...mapGetters("order", ["getDetailList"]),
    //获取订单信息
    orderInfo() {
      return this.$store.state.order.orderInfo;
    },
    //获取默认选择的地址信息
    address() {
      return (
        this.$store.state.order.address.find((item) => item.isDefault == 1) ||
        {}
      );
    },
  },
  mounted() {
    this.$store.dispatch("order/getUserAddress");
    this.$store.dispatch("order/getOrderInfo");
  },
  methods: {
    //提交订单
    async submitOrder() {
      const { getDetailList, msg } = this;
      const { tradeNo } = this.orderInfo; //发服务器的订单编号
      //发服务器的订单信息
      const data = {
        consignee: this.address.consignee,
        consigneeTel: this.address.phoneNum,
        deliveryAddress: this.address.fullAddress,
        paymentWay: "ONLINE",
        orderComment: msg,
        orderDetailList: getDetailList,
      };
      const res = await this.$API.reqSubmitOrder(tradeNo, data);
      //提交订单成功
      if (res.code == 200) {
        this.$router.push({ name: "Pay", params: { orderId: res.data } });
      } else {
        //提交订单失败
        this.$message({
          type: "error",
          message: res.message,
          center: true,
        });
      }
    },
  },
};
</script>

<style scoped lang="less">
.trade-box {
  width: 990px;
  margin: 0px auto;
  .title {
    font-size: 18px;
    line-height: 21px;
    margin-bottom: 10px;
  }
  .content {
    border: 1px solid rgb(221, 221, 221);
    padding: 25px;
    box-sizing: border-box;
    .pay-box {
      line-height: 36px;
      padding: 20px 0px;
      border-bottom: 1px solid rgb(221, 221, 221);
      .pay-title {
        font-size: 16px;
        font-weight: 800;
      }
      .pay-select {
        margin-left: 20px;
        span {
          display: inline-block;
          width: 150px;
          height: 30px;
          line-height: 30px;
          text-align: center;
          border: 1px solid #ddd;
          position: relative;
          margin-right: 20px;
        }
      }
    }
    .inventory-box {
      background: #f4f4f4;
      padding: 20px 0px;
      margin: 0 auto;
      .inventory-title {
        display: block;
        font-size: 16px;
        font-weight: 800;
      }
      .inventory-list {
        width: 100%;
        display: flex;
        flex-direction: row;
        .delive {
          width: 30%;
          padding: 20px;
          display: flex;
          flex-direction: column;
          border-right: 1px solid rgb(221, 221, 221);
          .delive-title {
            display: block;
            font-size: 13px;
          }
          .info {
            margin-top: 20px;
            display: flex;
            flex-direction: column;
            .s1 {
              float: left;
              border: 1px solid #ddd;
              width: 120px;
              height: 30px;
              line-height: 30px;
              margin-bottom: 20px;
              text-align: center;
            }
            p {
              margin-bottom: 20px;
            }
          }
          .s1 {
            display: inline-block;
            width: 150px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            border: 1px solid #ddd;
            position: relative;
            margin-right: 20px;
          }
        }
        .goods-list {
          width: 70%;
          padding-left: 20px;
          display: flex;
          flex-direction: column;
          .detail-title {
            display: block;
            font-size: 13px;
          }
          .detail {
            background: #feedef;
            padding-top: 15px;
            .list {
              display: flex;
              flex-direction: row;
              align-items: center;
              padding: 10px;
              border: 1px solid #ddd;
              li {
                padding-right: 10px;
              }
              .img-url {
                width: 15%;
                img {
                  width: 80px;
                  height: 80px;
                  text-align: center;
                }
              }
              .goods-name {
                width: 45%;
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                span {
                  display: inline-block;
                  margin-top: 10px;
                  color: red;
                }
              }
              .goods-price {
                width: 12%;
                text-align: center;
              }
              .goods-num {
                width: 10%;
                text-align: center;
              }
              .goods-stock {
                width: 10%;
                text-align: center;
              }
            }
          }
          .bbs {
            padding: 20px 0px;

            span {
              line-height: 50px;
              display: block;
              font-size: 13px;
            }
            textarea {
              width: 100%;
              padding: 5px;
              border-color: #e4e2e2;
              outline: none;
              resize: none;
            }
          }
        }
      }
    }
    .bill {
      border-top: 1px solid rgb(221, 221, 221);
      h5 {
        line-height: 50px;
      }
      div {
        padding-left: 15px;
      }
    }
    .money {
      border-top: 1px solid #ddd;
      padding: 20px auto;
      ul {
        width: 220px;
        float: right;
        li {
          line-height: 30px;
          display: flex;
          justify-content: space-between;
          i {
            color: red;
          }
        }
      }
    }
    .trade {
      box-sizing: border-box;
      padding: 10px;
      text-align: right;
      background-color: #f4f4f4;
      border-top: 1px solid #ddd;
      div {
        line-height: 30px;
      }
      .price span {
        color: #e12228;
        font-weight: 700;
        font-size: 14px;
      }
      .receiveInfo {
        color: #999;
      }
    }
    .sub {
      .subBtn {
        float: right;
        width: 164px;
        height: 56px;
        font: 700 18px "微软雅黑";
        line-height: 56px;
        text-align: center;
        color: #fff;
        background-color: #3498db;
      }
    }
  }
}
</style>
